<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle"
               @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
      :isExportExcel2="true"
      :exportFileName="'经销商账户台账.xlsx'"
    >
      <template slot="controls" slot-scope="props">
        <!-- <el-button size="small" type="primary" icon="el-icon-refresh" @click="refresh">刷新</el-button> -->
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="issearchKP"
      :title="'开票信息'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <invoice-information :rowData="formData"  @close="KPcloseHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import {getAccountdetail} from '@/api/partsmanage/financialManagement/StandingBook/index';
import invoiceInformation from '@/pages/partsmanage/financialManagement/StandingBook/invoiceInformation'
import { getCurrentUser } from '@/api/cms-api/origin/construct/dealer';
export default {
  name: "index",
  mixins: [dictionary],
  components: {invoiceInformation},
  data() {
    return{
      columns: this.createTableColumns(),
      topFilterList: this.createTopFilterList(),
      fetchApi: getAccountdetail,
      issearchKP: false,
      fetchParams: {
        shop: 'shop',
        xhrAbort: true
      },
    };
  },
  async created() {
    this.columns.find(x => x.dataIndex === 'bjpjsx').hidden = true;
    this.columns.find(x => x.dataIndex === 'bjpjsx').dictItems = this.createDictList('5000');
    // 获取当前登录人信息
    await getCurrentUser({}).then(response => {
      console.info(response);
      if (response.data.appId === 'beijing') {
        console.info(this.topFilterList);
        this.topFilterList.find(x => x.fieldName === 'bjpjsx').hidden = false;
        this.columns.find(x => x.dataIndex === 'bjpjsx').hidden = false;
      }
    });
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '凭证号',
          fieldName: 'xspzhm',
        },
        {type: 'SELECT', label: '油电属性', fieldName: 'bjpjsx', placeholder: '请选择', hidden: true, itemList: this.createDictList('5000')},
      ]
    },
    createTableColumns () {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '经销商代码',
          dataIndex: 'xskhdm',
          sorter: true,
        },
        {
          title: '经销商名称',
          dataIndex: 'xskhmc',
          sorter: true,
        },
        {
          title: '油电属性',
          dataIndex: 'bjpjsx',
          sorter: true,
        },
        {
          title: '信用控制范围',
          dataIndex: 'xskzfw',
          sorter: true,
        },
        {
          title: '凭证类别',
          dataIndex: 'xspzlb',
          sorter: true,
        },
        {
          title: '凭证日期',
          dataIndex: 'xspzrq',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
        },
        {
          title: '凭证号',
          dataIndex: 'xspzhm',
          sorter: true,
        },
        {
          title: '凭证年度',
          dataIndex: 'xspznd',
          sorter: true,
        },
        {
          title: '金税发票号',
          dataIndex: 'xsjsfp',
          sorter: true,
          render: props => {
            return <a style="color: blue;text-decoration:underline;" href="#" onClick={() => this.clickFP(props.row)}>{props.row.xsjsfp}</a>;
          }
        },
        {
          title: '凭证金额',
          dataIndex: 'xspzje',
          sorter: true,
          precision: 2,
        },
        {
          title: '备注',
          dataIndex: 'xtbeiz',
          sorter: true,
        },
        {
          title: '来款方向',
          dataIndex: 'xslkfx',
          sorter: true,
        }
      ]
    },
    clickFP(row){
      this.issearchKP = true
      this.formData = row
    },
    refresh() {
      if(this.fetchParams.xhrAbort){
        this.fetchParams.xhrAbort= false
      }else{
        this.$refs.table.DO_REFRESH(false);
      }
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    }
  }
}
</script>

<style scoped>

</style>
